import Vue from 'vue'
import App from './App'
import router from '@/router'
import store from '@/store'
import '@/assets/js/remChange'
import '@/assets/js/request'
import { wxConfig, updateShare } from '@/assets/js/wxenv'
import '@/assets/css/common.scss'
import config from '@/assets/js/config'
import tools from '@/assets/js/tools'
// import filters from '@/assets/js/filters'

Vue.config.productionTip = false

Vue.prototype.$config = config
Vue.prototype.$tools = tools

// Object.keys(filters).forEach(item => {
//   Vue.filter(item, filters[item])
// })
let touchEndTime

window.addEventListener('touchend', () => {
  touchEndTime = Date.now()
})

router.beforeEach((to, from, next) => {
  console.log('>>>', Date.now() - touchEndTime)
  // ios滑动切换
  if ((Date.now() - touchEndTime) > 50 && (Date.now() - touchEndTime) < 377) {
    store.commit('routerAni', '')
  } else {
    const toPathLen = to.path.length
    const fromPathLen = from.path.length
    let routerAni = toPathLen < fromPathLen ? 'slide-right' : 'slide-left'
    store.commit('routerAni', routerAni)
    document.querySelector('title').innerHTML = to.name
  }
  next()
})

// 路由变化重新配置微信分享
router.afterEach(to => {
  if (window.WeixinJSBridge) {
    wxConfig(() => updateShare())
  } else {
    document.addEventListener('WeixinJSBridgeReady', () => {
      // alert('WeixinJSBridge is ready')
      wxConfig(() => updateShare())
    }, false)
  }
})

/* eslint-disable no-new */
const app = new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
})
